home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 January / ChipCD_1.03.iso / zkuste / delphi / kolekce / d3456 / GmPrintSuite_2_61_Lite.exe / {app} / GmThumbnails.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2002-10-05  |  22.8 KB  |  790 lines

  1. {******************************************************************************}
  2. {                                                                              }
  3. {                         GmThumbnails.pas v2.61 Pro                           }
  4. {                                                                              }
  5. {           Copyright (c) 2001 Graham Murt  - www.MurtSoft.co.uk               }
  6. {                                                                              }
  7. {   Feel free to e-mail me with any comments, suggestions, bugs or help at:    }
  8. {                                                                              }
  9. {                           graham@murtsoft.co.uk                              }
  10. {                                                                              }
  11. {******************************************************************************}
  12.  
  13. unit GmThumbnails;
  14.  
  15. interface
  16.  
  17. uses
  18.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  19.   GmPreview, GmConst, Menus, GmTypes;
  20.  
  21. {$I GMPS.INC}
  22.  
  23. type
  24.   TOnThumbMouseDown = procedure (Sender: TObject; Button: TMouseButton;
  25.     Shift: TShiftState; APage: TGmPage) of object;
  26.  
  27.   TGmThumbnails = class;
  28.   TGmThumbnailList = class;
  29.  
  30.   TGmThumbNailLayout = (gmThumbHorz, gmThumbVert, gmThumbGrid);
  31.  
  32.   TGmThumbnail = class(TGmPaperImage)
  33.   private
  34.     FCaption: string;
  35.     FFont: TFont;
  36.     FPageNum: integer;
  37.     FSelected: Boolean;
  38.     FSelectedColor: TColor;
  39.     FShowCaption: Boolean;
  40.     FThumbList: TGmThumbnailList;
  41.     FThumbSize: integer;
  42.     FThumbSpacing: integer;
  43.     // events...
  44.     FOnClick: TThumbClickEvent;
  45.     FOnMouseDown: TThumbMouseDownEvent;
  46.     function ExpandCaption(ACaption: string): string;
  47.     procedure ResizeThumb;
  48.     procedure SetCaption(ACaption: string);
  49.     procedure SetFont(AFont: TFont);
  50.     procedure SetSelected(ASelected: Boolean);
  51.     procedure SetSelectedColor(AColor: TColor);
  52.   protected
  53.     procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: integer); override;
  54.     procedure Paint; override;
  55.   public
  56.     constructor Create(AOwner: TComponent); override;
  57.     destructor Destroy; override;
  58.     property Caption: string write SetCaption;
  59.     property Font: TFont read FFont write SetFont;
  60.     property Selected: Boolean read FSelected write SetSelected;
  61.     property SelectedColor: TColor read FSelectedColor write SetSelectedColor;
  62.     property ShowCaption: Boolean read FShowCaption write FShowCaption;
  63.     property OnThumbClick: TThumbClickEvent read FOnClick write FOnClick;
  64.     property OnThumbMouseDown: TThumbMouseDownEvent read FOnMouseDown write FOnMouseDown;
  65.   end;
  66.  
  67.   TGmThumbnailList = class
  68.   private
  69.     FCaptions: string;
  70.     FFont: TFont;
  71.     FPreview: TGmPreview;
  72.     FHighlight: Boolean;
  73.     FItemIndex: integer;
  74.     FScrollIntoView: Boolean;
  75.     FSelectedColor: TColor;
  76.     FShadow: TGmShadow;
  77.     FShowCaption: Boolean;
  78.     FThumbList: TList;
  79.     FThumbnails: TGmThumbnails;
  80.     // events...
  81.     FOnThumbMouseDown: TThumbMouseDownEvent;
  82.     function GetCount: integer;
  83.     function GetThumbnail(index: integer): TGmThumbnail;
  84.     procedure SetFont(AFont: TFont);
  85.     procedure SetHighlight(AValue: Boolean);
  86.     procedure SetItemIndex(index: integer);
  87.     procedure SetPageCaptions(ACaption: string);
  88.     procedure SetSelectedColor(AColor: TColor);
  89.     procedure SetShowCaption(AValue: Boolean);
  90.     procedure SetThumbnail(index: integer; AThumbnail: TGmThumbnail);
  91.     procedure ThumbClicked(Sender: TObject; AIndex: integer);
  92.     procedure ThumbMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; APage: TGmPage);
  93.   public
  94.     constructor Create(AThumbnails: TGmThumbnails);
  95.     destructor Destroy; override;
  96.     function AddThumb: TGmThumbnail;
  97.     procedure Clear;
  98.     procedure DeleteThumb(index: integer);
  99.     property Count: integer read GetCount;
  100.     property Font: TFont write SetFont;
  101.     property Highlight: Boolean read FHighlight write SetHighlight default True;
  102.     property ItemIndex: integer read FItemIndex write SetItemIndex;
  103.     property PageCaptions: string write SetPageCaptions;
  104.     property SelectedColor: TColor read FSelectedColor write SetSelectedColor;
  105.     property ShowCaption: Boolean read FShowCaption write SetShowCaption;
  106.     property ThumbNail[index: integer]: TGmThumbnail read GetThumbnail write SetThumbnail; default;
  107.     // events...
  108.     property OnThumbMouseDown: TThumbMouseDownEvent read FOnThumbMouseDown write FOnThumbMouseDown;
  109.   end;
  110.  
  111.   TGmThumbnails = class(TGmCustomThumbnails)
  112.   private
  113.     FBorderStyle: TBorderStyle;
  114.     FEnabled: Boolean;
  115.     FFont: TFont;
  116.     FGridWidth: integer;
  117.     FHighlight: Boolean;
  118.     FLayout: TGmThumbNailLayout;
  119.     FPageCaptions: string;
  120.     FPreview: TGmPreview;
  121.     FScrollIntoView: Boolean;
  122.     FSelectedColor: TColor;
  123.     FShadow: TGmShadow;
  124.     FShowCaption: Boolean;
  125.     FThumbnailList: TGmThumbnailList;
  126.     FThumbPopup: TPopupMenu;
  127.     FThumbSize: integer;
  128.     FThumbSpacing: integer;
  129.     // events...
  130.     FOnThumbMouseDown: TThumbMouseDownEvent;
  131.     function GetItemIndex: integer;
  132.     function SyncronizePages: Boolean;
  133.     procedure Redraw;
  134.     procedure SetBorderStyle(const Value: TBorderStyle);
  135.     procedure SetFont(AFont: TFont);
  136.     procedure SetGridWidth(AWidth: integer);
  137.     procedure SetHighlight(AValue: Boolean);
  138.     procedure SetItemIndex(AValue: integer);
  139.     procedure SetLayout(AValue: TGmThumbNailLayout);
  140.     procedure SetPageCaptions(ACaption: string);
  141.     procedure SetPreview(APreview: TGmPreview);
  142.     procedure SetScrollIntoView(AValue: Boolean);
  143.     procedure SetSelectedColor(AColor: TColor);
  144.     procedure SetShowCaption(AValue: Boolean);
  145.     procedure SetThumbPopup(APopupMenu: TPopupMenu);
  146.     procedure SetThumbSize(AValue: integer);
  147.     procedure SetThumbSpacing(AValue: integer);
  148.     //rocedure ThumbClicked(Sender: TObject; AIndex: integer);
  149.     procedure ThumbMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; APage: TGmPage);
  150.     { Private declarations }
  151.   protected
  152.     procedure CreateParams(var Params: TCreateParams); override;
  153.     procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  154.     procedure NumPagesChanged(var Message: TMessage); message GM_NUMPAGES_CHANGED;
  155.     procedure PreviewCleared(var Message: TMessage); message GM_PREVIEW_CLEARED;
  156.     procedure PreviewUpdated(var Message: TMessage); message GM_PREVIEW_UPDATED;
  157.     procedure PageChanged(var Message: TMessage); message GM_PAGE_CHANGED;
  158.     procedure PreviewBeginUpdate(var Message: TMessage); message GM_PREVIEW_BEGINUPDATE;
  159.     procedure PreviewEndUpdateUpdate(var Message: TMessage); message GM_PREVIEW_ENDUPDATE;
  160.     procedure SetEnabled(AValue: Boolean); {$IFDEF D4+} override; {$ENDIF}
  161.     { Protected declarations }
  162.   public
  163.     constructor Create(AOwner: TComponent); override;
  164.     destructor Destroy; override;
  165.     property ItemIndex: integer read GetItemIndex write SetItemIndex;
  166.     { Public declarations }
  167.   published
  168.     property Align;
  169.     {properties available from Delphi 4...}
  170.     {$IFDEF D4+}
  171.     property Anchors;
  172.     property Constraints;
  173.     {$ENDIF}
  174.     property Color default clGray;
  175.     property BorderStyle: TBorderStyle read FBorderStyle write SetBorderStyle default bsSingle;
  176.     property CaptionFont: TFont read FFont write SetFont;
  177.     property Enabled: Boolean read FEnabled write SetEnabled default True;
  178.     property GridWidth: integer read FGridWidth write SetGridWidth default 4;
  179.     property Highlight: Boolean read FHighlight write SetHighlight default True;
  180.     property Layout: TGmThumbNailLayout read FLayout write SetLayout default gmThumbHorz;
  181.     property PageCaptions: string read FPageCaptions write SetPageCaptions;
  182.     property PopupMenu;
  183.     property Preview: TGmPreview read FPreview write SetPreview;
  184.     property ScrollIntoView: Boolean read FScrollIntoView write SetScrollIntoView default True;
  185.     property SelectedColor: TColor read FSelectedColor write SetSelectedColor default clBlue;
  186.     property Shadow: TGmShadow read FShadow write FShadow;
  187.     property ShowCaption: Boolean read FShowCaption write SetShowCaption;
  188.     property ShowHint;
  189.     property TabOrder;
  190.     property ThumbPopup: TPopupMenu read FThumbPopup write SetThumbPopup;
  191.     property ThumbSize: integer read FThumbSize write SetThumbSize default 3;
  192.     property ThumbSpacing: integer read FThumbSpacing write SetThumbSpacing default 6;
  193.     property Visible;
  194.     // events...
  195.     property OnThumbMouseDown: TThumbMouseDownEvent read FOnThumbMouseDown write FOnThumbMouseDown;
  196.     { Published declarations }
  197.   end;
  198.  
  199. implementation
  200.  
  201. //------------------------------------------------------------------------------
  202.  
  203. { TGmThumbnail }
  204.  
  205. constructor TGmThumbnail.Create(AOwner: TComponent);
  206. begin
  207.   inherited Create(AOwner);
  208.   Gutter := 5;
  209.   Cursor := crHandPoint;
  210.   FSelected := False;
  211.   FThumbSize := 4;
  212. end;
  213.  
  214. destructor TGmThumbnail.Destroy;
  215. begin
  216.   inherited Destroy;
  217. end;
  218.  
  219. //------------------------------------------------------------------------------
  220.  
  221. // *** Private functions ***
  222.  
  223. function TGmThumbnail.ExpandCaption(ACaption: string): string;
  224. var
  225.   TokenIndex: integer;
  226. begin
  227.   Result := ACaption;
  228.   while Pos('#', Result) > 0 do
  229.   begin
  230.     TokenIndex := Pos('#', Result);
  231.     Delete(Result, TokenIndex, 1);
  232.     Insert(IntToStr(FPageNum), Result, TokenIndex);
  233.   end;
  234. end;
  235.  
  236. procedure TGmThumbnail.ResizeThumb;
  237. begin
  238.   if FShowCaption then
  239.     Borders := Rect(FThumbSpacing,
  240.                     FThumbSpacing,
  241.                     FThumbSpacing,
  242.                     (0-FFont.Height)+5)
  243.   else
  244.     Borders := Rect(FThumbSpacing,
  245.                     FThumbSpacing,
  246.                     FThumbSpacing,
  247.                     FThumbSpacing);
  248.   Width  := (Borders.Left + Borders.Right) + (Gutter * 2) + Round(Page.PageWidth.AsMillimeters / 18 * (FThumbSize+1));
  249.   Height := (Borders.Top + Borders.Bottom) + (Gutter * 2) + Round(Page.PageHeight.AsMillimeters / 18 * (FThumbSize+1));
  250. end;
  251.  
  252. procedure TGmThumbnail.SetCaption(ACaption: string);
  253. begin
  254.   if FCaption <> ACaption then
  255.   begin
  256.     FCaption := ACaption;
  257.     Invalidate;
  258.   end;
  259. end;
  260.  
  261. procedure TGmThumbnail.SetFont(AFont: TFont);
  262. begin
  263.   FFont := AFont;
  264.   ResizeThumb;
  265.   Invalidate;
  266. end;
  267.  
  268. procedure TGmThumbnail.SetSelected(ASelected: Boolean);
  269. begin
  270.   if (FSelected <> ASelected) or (ASelected = True) then
  271.   begin
  272.     FSelected := ASelected;
  273.     Invalidate;
  274.   end;
  275. end;
  276.  
  277. procedure TGmThumbnail.SetSelectedColor(AColor: TColor);
  278. begin
  279.   if FSelectedColor <> AColor then
  280.   begin
  281.     FSelectedColor := AColor;
  282.     if FSelected then Invalidate;
  283.   end;
  284. end;
  285.  
  286. //------------------------------------------------------------------------------
  287.  
  288. procedure TGmThumbnail.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: integer);
  289. begin
  290.   if Assigned(FOnMouseDown) then FOnMouseDown(Self, Button, Shift, Page);
  291.   if Button = mbLeft then
  292.     if Assigned(FOnClick) then FOnClick(Self, Page.PageNum);
  293. end;
  294.  
  295. procedure TGmThumbnail.Paint;
  296. var
  297.   ACaption: string;
  298. begin
  299.   if FThumbList.FThumbnails.Enabled then
  300.     inherited
  301.   else
  302.   begin
  303.     Canvas.Brush.Color := clWhite;
  304.     Canvas.Rectangle(PageRect.Left, PageRect.Top, PageRect.Right, PageRect.Bottom);
  305.   end;
  306.   Canvas.Brush.Style := bsClear;
  307.   if FSelected then
  308.     Canvas.Pen.Color := FSelectedColor
  309.   else
  310.     Canvas.Pen.Color := clBlack;
  311.   Canvas.Rectangle(PageRect.Left, PageRect.Top, PageRect.Right, PageRect.Bottom);
  312.   if FShowCaption then
  313.   begin
  314.     ACaption := ExpandCaption(FCaption);
  315.     Canvas.Font.Assign(FFont);
  316.     Canvas.Font.Color := Canvas.Pen.Color;
  317.     Canvas.TextOut((Width - Canvas.TextWidth(ACaption)) div 2,
  318.                    Height - (Canvas.TextHeight(ACaption)+2),
  319.                    ACaption);
  320.   end;
  321. end;
  322.  
  323. //------------------------------------------------------------------------------
  324.  
  325.  
  326.  
  327. { TGmThumbnailList }
  328.  
  329. constructor TGmThumbnailList.Create(AThumbnails: TGmThumbnails);
  330. begin
  331.   inherited Create;
  332.   FThumbnails := AThumbnails;
  333.   FThumbList := TList.Create;
  334.   FHighlight := True;
  335. end;
  336.  
  337. destructor TGmThumbnailList.Destroy;
  338. begin
  339.   Clear;
  340.   FThumbList.Free;
  341.   inherited Destroy;
  342. end;
  343.  
  344. //------------------------------------------------------------------------------
  345.  
  346. // *** Private functions ***
  347.  
  348. function TGmThumbnailList.GetCount: integer;
  349. begin
  350.   Result := FThumbList.Count;
  351. end;
  352.  
  353. function TGmThumbnailList.GetThumbnail(index: integer): TGmThumbnail;
  354. begin
  355.   Result := TGmThumbnail(FThumbList[index]);
  356. end;
  357.  
  358. procedure TGmThumbnailList.SetFont(AFont: TFont);
  359. var
  360.   ICount: integer;
  361. begin
  362.   for ICount := 0 to FThumbList.Count-1 do
  363.     ThumbNail[ICount].Font := AFont;
  364.   FFont := AFont;
  365. end;
  366.  
  367. procedure TGmThumbnailList.SetHighlight(AValue: Boolean);
  368. begin
  369.   if FHighlight <> AValue then
  370.   begin
  371.     FHighlight := AValue;
  372.     SetSelectedColor(FSelectedColor);
  373.   end;
  374. end;
  375.  
  376. procedure TGmThumbnailList.SetItemIndex(index: integer);
  377. var
  378.   ICount: integer;
  379. begin
  380.   if Index < 1 then Exit;
  381.   for ICount := 0 to FThumbList.Count-1 do
  382.     ThumbNail[ICount].Selected := ICount = index-1;
  383.   if FScrollIntoView then FThumbnails.ScrollInView(ThumbNail[index-1]);
  384.   FPreview.CurrentPage := index;
  385. end;
  386.  
  387. procedure TGmThumbnailList.SetPageCaptions(ACaption: string);
  388. var
  389.   ICount: integer;
  390. begin
  391.   for ICount := 0 to FThumbList.Count-1 do
  392.     ThumbNail[ICount].Caption := ACaption;
  393.   FCaptions := ACaption;
  394. end;
  395.  
  396. procedure TGmThumbnailList.SetSelectedColor(AColor: TColor);
  397. var
  398.   ICount: integer;
  399.   NewColor: TColor;
  400. begin
  401.   if FHighlight then NewColor := AColor else NewColor := clBlack;
  402.   for ICount := 0 to FThumbList.Count-1 do
  403.     ThumbNail[ICount].SelectedColor := NewColor;
  404.   FSelectedColor := AColor;
  405. end;
  406.  
  407. procedure TGmThumbnailList.SetShowCaption(AValue: Boolean);
  408. var
  409.   ICount: integer;
  410. begin
  411.   for ICount := 0 to FThumbList.Count-1 do
  412.     ThumbNail[ICount].ShowCaption := AValue;
  413.   FShowCaption := AValue;
  414. end;
  415.  
  416. procedure TGmThumbnailList.SetThumbnail(index: integer; AThumbnail: TGmThumbnail);
  417. begin
  418.   FThumbList[index] := AThumbnail;
  419. end;
  420.  
  421. procedure TGmThumbnailList.ThumbClicked(Sender: TObject; AIndex: integer);
  422. begin
  423.   ItemIndex := AIndex;
  424. end;
  425.  
  426. procedure TGmThumbnailList.ThumbMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; APage: TGmPage);
  427. begin
  428.   if Assigned(FOnThumbMouseDown) then FOnThumbMouseDown(Sender, Button, Shift, APage);
  429. end;
  430.  
  431. //------------------------------------------------------------------------------
  432.  
  433. // *** Public functions ***
  434.  
  435. function TGmThumbnailList.AddThumb: TGmThumbnail;
  436. begin
  437.   Result := TGmThumbnail.Create(FThumbnails);
  438.   Result.FThumbList := Self;
  439.   Result.Shadow := FShadow;
  440.   Result.OnThumbClick := ThumbClicked;
  441.   Result.OnThumbMouseDown := ThumbMouseDown;
  442.   Result.FShowCaption := FThumbnails.ShowCaption;
  443.   Result.FCaption := FCaptions;
  444.   Result.FFont := FFont;
  445.   Result.FSelectedColor := FSelectedColor;
  446.   Result.FThumbSize := FThumbnails.ThumbSize;
  447.   Result.PopupMenu := FThumbnails.ThumbPopup;
  448.   FThumbList.Add(Result);
  449. end;
  450.  
  451. procedure TGmThumbnailList.Clear;
  452. var
  453.   ICount: integer;
  454. begin
  455.   for ICount := FThumbList.Count-1 downto 0 do
  456.     DeleteThumb(ICount);
  457.   FThumbList.Clear;
  458. end;
  459.  
  460. procedure TGmThumbnailList.DeleteThumb(index: integer);
  461. begin
  462.   TGmThumbnail(FThumbList[index]).Free;
  463.   FThumbList.Delete(index);
  464. end;
  465.  
  466. //------------------------------------------------------------------------------
  467.  
  468. { TGmThumbnails }
  469.  
  470. constructor TGmThumbnails.Create(AOwner: TComponent);
  471. begin
  472.   inherited Create(AOwner);
  473.   FShadow := TGmShadow.Create;
  474.   FThumbnailList := TGmThumbnailList.Create(Self);
  475.   FFont := TFont.Create;
  476.  
  477.   // set events...
  478.   FThumbnailList.OnThumbMouseDown := ThumbMouseDown;
  479.  
  480.   // link objects...
  481.   FThumbnailList.FPreview := FPreview;
  482.   FThumbnailList.FShadow := FShadow;
  483.   FThumbnailList.Font := FFont;
  484.  
  485.   // properties...
  486.   FEnabled := True;
  487.   Width := 240;
  488.   Height := 115;
  489.   FBorderStyle := bsSingle;
  490.   FGridWidth := 4;
  491.   ScrollIntoView := True;
  492.   SelectedColor := clBlue;
  493.   FShadow.Width := 3;
  494.   FShowCaption := True;
  495.   FThumbSize := 3;
  496.   FThumbSpacing := 6;
  497.   PageCaptions := DEFAULT_PAGE_CAPTION;
  498.   Color := clGray;
  499.   FHighlight := True;
  500. end;
  501.  
  502. destructor TGmThumbnails.Destroy;
  503. begin
  504.   FFont.Free;
  505.   FThumbnailList.Free;
  506.   FShadow.Free;
  507.   inherited Destroy;
  508. end;
  509.  
  510. //------------------------------------------------------------------------------
  511.  
  512. // *** Private functions ***
  513.  
  514. function TGmThumbnails.GetItemIndex: integer;
  515. begin
  516.   Result := FThumbnailList.ItemIndex;
  517. end;
  518.  
  519. function TGmThumbnails.SyncronizePages: Boolean;
  520. begin
  521.   Result := False;
  522.   if FPreview.NumPages = FThumbnailList.Count then Exit;
  523.   while FThumbnailList.Count < FPreview.NumPages do
  524.     FThumbnailList.AddThumb;
  525.   while FThumbnailList.Count > FPreview.NumPages do
  526.     FThumbnailList.DeleteThumb(FThumbnailList.Count-1);
  527.   Result := True;
  528. end;
  529.  
  530. procedure TGmThumbnails.Redraw;
  531. var
  532.   ICount: integer;
  533.   AStartPoint: TPoint;
  534.   APoint: TPoint;
  535.   AThumb: TGmThumbnail;
  536. begin
  537.   if not Assigned(FPreview) then Exit;
  538.   DisableAutoRange;
  539.   try
  540.     SyncronizePages;
  541.     AStartPoint := Point(0-HorzScrollBar.Position,0-VertScrollBar.Position);
  542.     APoint := AStartPoint;
  543.     for ICount := 0 to FThumbnailList.Count-1 do
  544.     begin
  545.       AThumb := FThumbnailList.Thumbnail[ICount];
  546.       AThumb.Page := FPreview.Pages[ICount+1];
  547.       AThumb.FPageNum := ICount+1;
  548.       AThumb.ResizeThumb;
  549.       AThumb.Left := APoint.x;
  550.       AThumb.Top := APoint.y;
  551.       if not AThumb.HasParent then
  552.         AThumb.Parent := Self;
  553.  
  554.       //Inc(APoint.x, AThumb.Width);
  555.       case FLayout of
  556.         gmThumbHorz: Inc(APoint.x, AThumb.Width);
  557.         gmThumbVert: Inc(APoint.y, AThumb.Height);
  558.         gmThumbGrid:
  559.         begin
  560.           Inc(APoint.x, AThumb.Width);
  561.           if (ICount+1) mod (FGridWidth) = 0 then
  562.           begin
  563.             APoint.x := AStartPoint.x;
  564.             Inc(APoint.y, AThumb.Height);
  565.           end;
  566.         end;
  567.       end;
  568.     end;
  569.   finally
  570.     EnableAutoRange;
  571.     FThumbnailList.ItemIndex := FPreview.CurrentPage;
  572.   end;
  573. end;
  574.  
  575. procedure TGmThumbnails.SetBorderStyle(const Value: TBorderStyle);
  576. begin
  577.   if FBorderStyle <> Value then
  578.   begin
  579.     FBorderStyle := Value;
  580.     RecreateWnd;
  581.   end;
  582. end;
  583.  
  584. procedure TGmThumbnails.SetEnabled(AValue: Boolean);
  585. begin
  586.   inherited;
  587.   if FEnabled = AValue then Exit;
  588.   FEnabled := AValue;
  589.   if FEnabled then
  590.   begin
  591.     Redraw;
  592.     Invalidate;
  593.   end;
  594. end;
  595.  
  596. procedure TGmThumbnails.SetFont(AFont: TFont);
  597. begin
  598.   FFont.Assign(AFont);
  599.   FThumbnailList.Font := FFont;
  600.   Redraw;
  601. end;
  602.  
  603. procedure TGmThumbnails.SetGridWidth(AWidth: integer);
  604. begin
  605.   if FGridWidth <> AWidth then
  606.   begin
  607.     FGridWidth := AWidth;
  608.     FLayout := gmThumbGrid;
  609.     Redraw;
  610.   end;
  611. end;
  612.  
  613. procedure TGmThumbnails.SetHighlight(AValue: Boolean);
  614. begin
  615.   if FHighlight <> AValue then
  616.   begin
  617.     FHighlight := AValue;
  618.     FThumbnailList.Highlight := FHighlight;
  619.     Invalidate;
  620.   end;
  621. end;
  622.  
  623. procedure TGmThumbnails.SetItemIndex(AValue: integer);
  624. begin
  625.   FThumbnailList.ItemIndex := AValue;
  626. end;
  627.  
  628. procedure TGmThumbnails.SetLayout(AValue: TGmThumbNailLayout);
  629. begin
  630.   if FLayout <> AValue then
  631.   begin
  632.     FLayout := AValue;
  633.     Redraw;
  634.   end;
  635. end;
  636.  
  637. procedure TGmThumbnails.SetPageCaptions(ACaption: string);
  638. begin
  639.   if FPageCaptions <> ACaption then
  640.   begin
  641.     FPageCaptions := ACaption;
  642.     FThumbnailList.PageCaptions := FPageCaptions;
  643.   end;
  644. end;
  645.  
  646. procedure TGmThumbnails.SetPreview(APreview: TGmPreview);
  647. begin
  648.   if Assigned(FPreview) then
  649.   begin
  650.     FPreview.RemoveAssociatedComponent(Self);
  651.     FThumbnailList.Clear;
  652.   end;
  653.   FPreview := APreview;
  654.   FThumbnailList.FPreview := APreview;
  655.   if Assigned(FPreview) then
  656.   begin
  657.     FPreview.AddAssociatedComponent(Self);
  658.     Redraw;
  659.   end;
  660. end;
  661.  
  662. procedure TGmThumbnails.SetScrollIntoView(AValue: Boolean);
  663. begin
  664.   if FScrollIntoView <> AValue then
  665.   begin
  666.     FScrollIntoView := AValue;
  667.     FThumbnailList.FScrollIntoView := FScrollIntoView;
  668.   end;
  669. end;
  670.  
  671. procedure TGmThumbnails.SetSelectedColor(AColor: TColor);
  672. begin
  673.   if FSelectedColor <> AColor then
  674.   begin
  675.     FSelectedColor := AColor;
  676.     FThumbnailList.SelectedColor := AColor;
  677.     Invalidate;
  678.   end;
  679. end;
  680.  
  681. procedure TGmThumbnails.SetShowCaption(AValue: Boolean);
  682. begin
  683.   if FShowCaption <> AValue then
  684.   begin
  685.     FShowCaption := AValue;
  686.     FThumbnailList.ShowCaption := FShowCaption;
  687.     Redraw;
  688.   end;
  689. end;
  690.  
  691. procedure TGmThumbnails.SetThumbPopup(APopupMenu: TPopupMenu);
  692. var
  693.   ICount: integer;
  694. begin
  695.   FThumbPopup := APopupMenu;
  696.   for ICount := 0 to FThumbnailList.Count-1 do
  697.     FThumbnailList[ICount].PopupMenu := FThumbPopup;
  698. end;
  699.  
  700. procedure TGmThumbnails.SetThumbSize(AValue: integer);
  701. var
  702.   ICount: integer;
  703. begin
  704.   if FThumbSize <> AValue then
  705.   begin
  706.     FThumbSize := AValue;
  707.     for ICount := 0 to FThumbnailList.Count-1 do
  708.       FThumbnailList[ICount].FThumbSize := FThumbSize;
  709.     Redraw;
  710.   end;
  711. end;
  712.  
  713. procedure TGmThumbnails.SetThumbSpacing(AValue: integer);
  714. var
  715.   ICount: integer;
  716. begin
  717.   if FThumbSpacing <> AValue then
  718.   begin
  719.     FThumbSpacing := AValue;
  720.     for ICount := 0 to FThumbnailList.Count-1 do
  721.       FThumbnailList[ICount].FThumbSpacing := FThumbSpacing;
  722.     Redraw;
  723.   end;
  724. end;
  725.  
  726. procedure TGmThumbnails.ThumbMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; APage: TGmPage);
  727. begin
  728.   if Assigned(FOnThumbMouseDown) then FOnThumbMouseDown(Self, Button, Shift, APage);
  729. end;
  730.  
  731. //------------------------------------------------------------------------------
  732.  
  733. procedure TGmThumbnails.CreateParams(var Params: TCreateParams);
  734. const
  735.   BorderStyles: array[TBorderStyle] of DWORD = (0, WS_BORDER);
  736. begin
  737.   inherited CreateParams(Params);
  738.   with Params do
  739.   begin
  740.     Style := Style or BorderStyles[FBorderStyle];
  741.     if NewStyleControls and Ctl3D and (FBorderStyle = bsSingle) then
  742.     begin
  743.       Style := Style and not WS_BORDER;
  744.       ExStyle := ExStyle or WS_EX_CLIENTEDGE;
  745.     end;
  746.   end;
  747. end;
  748.  
  749. procedure TGmThumbnails.Notification(AComponent: TComponent; Operation: TOperation);
  750. begin
  751.   inherited Notification(AComponent, Operation);
  752.   if (Operation = opRemove) and (AComponent = FPreview) then
  753.   begin
  754.     FPreview := nil;
  755.     FThumbnailList.Clear;
  756.   end;
  757. end;
  758.  
  759. procedure TGmThumbnails.NumPagesChanged(var Message: TMessage);
  760. begin
  761.   Redraw;
  762. end;
  763.  
  764. procedure TGmThumbnails.PreviewCleared(var Message: TMessage);
  765. begin
  766.   Invalidate;
  767. end;
  768.  
  769. procedure TGmThumbnails.PreviewUpdated(var Message: TMessage);
  770. begin
  771.   Redraw;
  772. end;
  773.  
  774. procedure TGmThumbnails.PageChanged(var Message: TMessage);
  775. begin
  776.   Redraw;
  777. end;
  778.  
  779. procedure TGmThumbnails.PreviewBeginUpdate(var Message: TMessage);
  780. begin
  781.   Enabled := False;
  782. end;
  783.  
  784. procedure TGmThumbnails.PreviewEndUpdateUpdate(var Message: TMessage);
  785. begin
  786.   Enabled := True;
  787. end;
  788.  
  789. end.
  790.